package com.mzj.saas.mservice.lock.Repository;

import com.mzj.saas.mservice.lock.entity.SmartLockBle;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface SmartLockBleRepository extends PagingAndSortingRepository<SmartLockBle, Long>, JpaSpecificationExecutor<SmartLockBle> {
    @Transactional
    void deleteByLockAuthId(Long lockAuthId);

    SmartLockBle findByLockAuthId(Long lockAuthId);

    List<SmartLockBle> findByLockId(Long lockId);

    int deleteByLockId(Long lockId);

    SmartLockBle findByLockIdAndFAppUserId(Long lockId, String fAppUserId);

    @Transactional
    @Modifying
    @Query(value = "UPDATE saas_smart_lock_ble set identification=?1 where id=?2", nativeQuery = true)
    int setIdentification(String identification, Long id);
}
